package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteChapterOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocChapterDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.VocChapterCommand;
import com.cskaoyan.wordmemorize.request.VocChapterPageRequest;
import com.cskaoyan.wordmemorize.service.VocChapterService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/voc")
public class AdminVocChapterController {

    @Resource
    VocChapterService vocChapterService;

    // 添加章节
    @PostMapping("/chapter")
    public Result<Object> addChapter(@RequestBody VocChapterCommand command) {
        vocChapterService.addChapter(command);
        return Result.ok("添加成功");
    }

    // 修改章节
    @PutMapping("/chapter")
    public Result<Object> updateChapter(@RequestBody VocChapterCommand command) {
        vocChapterService.updateChapter(command);
        return Result.ok("更新成功");
    }

    // 分页查询章节列表
    @GetMapping("/chapters/list")
    public Result<PageDTO<VocChapterDTO>> getChapterList(VocChapterPageRequest pageRequest) {
        PageDTO<VocChapterDTO> chapterList = vocChapterService.getChapterPage(pageRequest);
        return Result.ok(chapterList);
    }

    // 批量删除章节
    @DeleteMapping("/chapters")
    public Result<List<DeleteChapterOperateDTO>> deleteChapters(@RequestBody BatchDeleteCommand command) {
        List<DeleteChapterOperateDTO> deleteChapterOperateDTOS = vocChapterService.deleteChapters(command);
        return Result.ok(deleteChapterOperateDTOS);
    }

    // 删除指定章节
    @DeleteMapping("/chapter/{chapterId}")
    public Result<DeleteChapterOperateDTO> deleteChapter(@PathVariable Long chapterId) {
        DeleteChapterOperateDTO deleteChapterOperateDTO = vocChapterService.deleteChapter(chapterId);
        return Result.ok(deleteChapterOperateDTO);
    }
}
